<?php
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use app\blog\model\StaffModel;
use think\Db;

class StaffController extends AdminBaseController
{
    //员工列表
    public function index(){
        //查询手机号，昵称
        $request = input('request.');
        $keywordComplex = [];
        if(!empty($request['user_login'])){
            $keyword = $request['user_login'];
            $keywordComplex['a.mobile'] = ['like',"%$keyword%"];
        }
        $data = new StaffModel();
        $list = $data->StaffList($keywordComplex);
        //查询保持分页不变
        $list->appends($request);
        $this->assign("list",$list);
        $this->assign("page",$list);
        return $this->fetch();
    }

    //新增员工
    public function add(){
        return $this->fetch();
    }
    public function addpost(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $bian = new StaffModel();
            $result = $bian->StaffPostAdd($data);
            if($result){
                $this->success("员工添加成功","blog/Staff/index");
            }else{
                $this->error("员工添加失败","blog/Staff/add");
            }
        }else{
            $this->error(lang('ERROR'));
        }
    }
    //获取修改员工历史数据
    public function edit(){
        $m_guid = $this->request->param("nav_id");
        $data = new StaffModel();
        $list = $data->StaffHistory($m_guid);
        $this->assign('list',$list);
        $this->assign('m_guid',$m_guid);
        return $this->fetch();
    }
    //获取修改员工的数据
    public function editpost(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $ergodic = new StaffModel();
            $result = $ergodic->StaffEditPost($data);
            if($result){
                $this->success("员工修改成功","blog/Staff/index");
            }else{
                $this->error("员工修改失败","blog/Staff/edit");
            }
        }else{
            $this->error(lang('ERROR'));
        }
    }
    //删除员工
    public function deletego(){
        //获取删除的m_guid,获取唯一标识
        $m_guid = $this->request->param('nav_id');
        $ergodic = new StaffModel();
        $result = $ergodic->StaffDelete($m_guid);
        if($result){
            $this->success("员工删除成功","blog/Staff/index");
        }else{
            $this->error("员工修改失败","blog/Staff/index");
        }
    }
}